package com.hdaccp.xingmu.MyRealm;

import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

public class Realm extends AuthorizingRealm {
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        String name = (String) principalCollection.getPrimaryPrincipal();
        SimpleAuthorizationInfo info = new SimpleAuthorizationInfo() ;
        info.addStringPermission("user:add");
        return info;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {

        String name = "haoran";
        String pass = "123";

        UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;

        String uname = token.getUsername();


        if(!name.equals(uname)){
            return null;
        }

        SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(name,pass,"");

        return info;






    }
}
